package com.yuehuanghun.admin.generator.model.generator;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yuehuanghun.framework.util.StringUtils;

@Component
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class PostgresqlTableGenerator extends AbstractTableGenerator {

	@Override
	public String getDbName() {
		return "postgresql";
	}
	
	private String getConnectedDatabase() {
		return jdbcTemplate.queryForObject("select current_database()", String.class);
	}

	@Override
	public String getCatalog() {
		if(StringUtils.isBlank(this.catalog)) {
			this.catalog = getConnectedDatabase();
		}
		return this.catalog;
	}
}
